<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>Abel&#39;Blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="Abel&#39;Blog">
<meta property="og:url" content="http://example.com/page/5/index.html">
<meta property="og:site_name" content="Abel&#39;Blog">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="Abel Sean">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="Abel&#39;Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Abel&#39;Blog</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-2018/2018-11-21-golang-socket" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/11/21/2018/2018-11-21-golang-socket/" class="article-date">
  <time datetime="2018-11-20T16:00:00.000Z" itemprop="datePublished">2018-11-21</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/11/21/2018/2018-11-21-golang-socket/">golang socket 尝试</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>收集一些golang常用的一些技术。</p>
<hr>
<ul>
<li><a href="#%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%83%A8%E5%88%86">服务器部分</a></li>
<li><a href="#%E5%AE%A2%E6%88%B7%E7%AB%AF%E9%83%A8%E5%88%86">客户端部分</a></li>
<li><a href="#%E9%80%9A%E8%BF%87%E8%AE%A9%E4%B8%BB%E7%BA%BF%E7%A8%8B%E7%AD%89%E5%BE%85%E4%BA%8B%E4%BB%B6">通过让主线程等待事件</a></li>
<li><a href="#%E6%95%B0%E6%8D%AE%E8%A7%A3%E6%9E%90%E5%A1%AB%E6%8A%A5%E4%BB%A3%E7%A0%81">数据解析、填报代码</a></li>
<li><a href="#%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE%E7%9A%84%E5%AE%9E%E4%BE%8B">发送数据的实例</a></li>
<li><a href="#%E7%9F%A5%E8%AF%86%E7%82%B9">知识点：</a></li>
</ul>
<p><a target="_blank" rel="noopener" href="https://github.com/name5566/leaf">参考【leaf】</a> 初步学着编写一个tcp服务器，一个连接他的client。</p>
<h1 id="服务器部分"><a href="#服务器部分" class="headerlink" title="服务器部分"></a>服务器部分</h1><figure class="highlight golang"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;net&quot;</span></span><br><span class="line">	<span class="string">&quot;os&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">Start</span><span class="params">()</span></span> &#123;</span><br><span class="line">	l, err := net.Listen(<span class="string">&quot;tcp&quot;</span>, <span class="string">&quot;127.0.0.1:8866&quot;</span>)</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">		fmt.Println(err.Error())</span><br><span class="line">		<span class="keyword">return</span></span><br><span class="line">	&#125;</span><br><span class="line">  <span class="keyword">go</span> main_loop(l)</span><br><span class="line">  </span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main_loop</span><span class="params">(l net.Listener)</span></span> &#123;</span><br><span class="line">	<span class="keyword">for</span> &#123;</span><br><span class="line">		conn, err := l.Accept()</span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">			fmt.Println(err.Error())</span><br><span class="line">			<span class="keyword">continue</span></span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">go</span> client_loop(conn)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">client_loop</span><span class="params">(conn net.Conn)</span></span> &#123;</span><br><span class="line">	fmt.Println(conn.RemoteAddr().String())</span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h1 id="客户端部分"><a href="#客户端部分" class="headerlink" title="客户端部分"></a>客户端部分</h1><figure class="highlight golang"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;net&quot;</span></span><br><span class="line">)</span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	conn, err := net.Dial(<span class="string">&quot;tcp&quot;</span>, <span class="string">&quot;127.0.0.1:8866&quot;</span>)</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">		fmt.Println(err)</span><br><span class="line">		<span class="keyword">return</span></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">go</span> handleClient(conn)</span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">handleClient</span><span class="params">(conn net.Conn)</span></span> &#123;</span><br><span class="line">  <span class="comment">//....</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="通过让主线程等待事件"><a href="#通过让主线程等待事件" class="headerlink" title="通过让主线程等待事件"></a>通过让主线程等待事件</h1><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;os/signal&quot;</span></span><br><span class="line">)</span><br><span class="line">	</span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	c := <span class="built_in">make</span>(<span class="keyword">chan</span> os.Signal, <span class="number">1</span>)</span><br><span class="line">	signal.Notify(c, os.Interrupt, os.Kill)</span><br><span class="line">	sig := &lt;-c</span><br><span class="line">	fmt.Println(sig.String())</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="数据解析、填报代码"><a href="#数据解析、填报代码" class="headerlink" title="数据解析、填报代码"></a>数据解析、填报代码</h1><p>下面的代码是简单的从socket里面读取数据，在数据头上增加一个头，little-endian方式的uint16。后面是一块数据.</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;encoding/binary&quot;</span></span><br><span class="line">	<span class="string">&quot;errors&quot;</span></span><br><span class="line">	<span class="string">&quot;io&quot;</span></span><br><span class="line">	<span class="string">&quot;net&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="comment">// --------------</span></span><br><span class="line"><span class="comment">// | len | data |</span></span><br><span class="line"><span class="comment">// --------------</span></span><br><span class="line"><span class="keyword">type</span> MsgPack <span class="keyword">struct</span> &#123;</span><br><span class="line">	maxMsgLen    <span class="keyword">uint16</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">NewMsgPack</span><span class="params">()</span> *<span class="title">MsgPack</span></span> &#123;</span><br><span class="line">	p := <span class="built_in">new</span>(MsgPack)</span><br><span class="line">	p.maxMsgLen = <span class="number">4096</span></span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> p</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="params">(c *MsgPack)</span> <span class="title">ReadPack</span><span class="params">(session net.Conn)</span> <span class="params">([]<span class="keyword">byte</span>, error)</span></span> &#123;</span><br><span class="line">	<span class="keyword">var</span> headData []<span class="keyword">byte</span> = <span class="built_in">make</span>([]<span class="keyword">byte</span>, <span class="number">2</span>)</span><br><span class="line">	<span class="keyword">if</span> _, err := io.ReadFull(session, headData); err != <span class="literal">nil</span> &#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="literal">nil</span>, err</span><br><span class="line">	&#125;</span><br><span class="line">	msgLen := <span class="keyword">uint16</span>(binary.LittleEndian.Uint16(headData))</span><br><span class="line">	<span class="keyword">if</span> msgLen &gt; c.maxMsgLen &#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="literal">nil</span>, errors.New(<span class="string">&quot;message too long&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	msgData := <span class="built_in">make</span>([]<span class="keyword">byte</span>, msgLen)</span><br><span class="line">	<span class="keyword">if</span> _, err := io.ReadFull(session, msgData); err != <span class="literal">nil</span> &#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="literal">nil</span>, err</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> msgData, <span class="literal">nil</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// goroutine safe</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="params">(p *MsgPack)</span> <span class="title">WritePack</span><span class="params">(conn net.Conn, args ...[]<span class="keyword">byte</span>)</span> <span class="title">error</span></span> &#123;</span><br><span class="line">	<span class="comment">// get len</span></span><br><span class="line">	<span class="keyword">var</span> msgLen <span class="keyword">uint16</span></span><br><span class="line">	<span class="keyword">for</span> i := <span class="number">0</span>; i &lt; <span class="built_in">len</span>(args); i++ &#123;</span><br><span class="line">		msgLen += <span class="keyword">uint16</span>(<span class="built_in">len</span>(args[i]))</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// check len</span></span><br><span class="line">	<span class="keyword">if</span> msgLen &gt; p.maxMsgLen &#123;</span><br><span class="line">		<span class="keyword">return</span> errors.New(<span class="string">&quot;message too long&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	msg := <span class="built_in">make</span>([]<span class="keyword">byte</span>, <span class="keyword">uint32</span>(<span class="number">2</span>)+<span class="keyword">uint32</span>(msgLen))</span><br><span class="line"></span><br><span class="line">	<span class="comment">// write len</span></span><br><span class="line">	binary.LittleEndian.PutUint16(msg, <span class="keyword">uint16</span>(msgLen))</span><br><span class="line"></span><br><span class="line">	<span class="comment">// write data</span></span><br><span class="line">	l := <span class="number">2</span></span><br><span class="line">	<span class="keyword">for</span> i := <span class="number">0</span>; i &lt; <span class="built_in">len</span>(args); i++ &#123;</span><br><span class="line">		<span class="built_in">copy</span>(msg[l:], args[i])</span><br><span class="line">		l += <span class="built_in">len</span>(args[i])</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	conn.Write(msg)</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> <span class="literal">nil</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h1 id="发送数据的实例"><a href="#发送数据的实例" class="headerlink" title="发送数据的实例"></a>发送数据的实例</h1><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">buf := []<span class="keyword">byte</span>(<span class="string">&quot;hello dial person! abel is online!&quot;</span>)</span><br><span class="line">pack.WritePack(conn, buf)</span><br></pre></td></tr></table></figure>

<h1 id="知识点："><a href="#知识点：" class="headerlink" title="知识点："></a>知识点：</h1><ul>
<li>通过struct组织数据结构</li>
<li>启动go里面的一个进程来处理数据包</li>
<li>挂载signal处理</li>
<li>tcp的包拆解</li>
<li>大端小端解析integer的基本用法</li>
<li>报错处理</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2018/11/21/2018/2018-11-21-golang-socket/" data-id="ckrn3an6v000720xwhylx5tmd" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/golang/" rel="tag">golang</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-2018/2018-11-20-nodejs-login" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/11/20/2018/2018-11-20-nodejs-login/" class="article-date">
  <time datetime="2018-11-19T16:00:00.000Z" itemprop="datePublished">2018-11-20</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/11/20/2018/2018-11-20-nodejs-login/">node.js http 尝试</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>收集一些node.js常用的一些技术。</p>
<ul>
<li><a href="#1-%E5%88%9D%E5%A7%8B%E5%8C%96express%E5%81%9Ahttp%E6%9C%8D%E5%8A%A1%E5%99%A8">1. 初始化express做http服务器</a></li>
<li><a href="#2-%E6%8F%90%E4%BE%9B%E4%B8%80%E4%B8%AApost%E5%A4%84%E7%90%86%E5%87%BD%E6%95%B0">2. 提供一个post处理函数</a></li>
<li><a href="#3-md5-hash">3. md5 hash</a></li>
<li><a href="#4-mysql">4. mysql</a></li>
</ul>
<h1 id="1-初始化express做http服务器"><a href="#1-初始化express做http服务器" class="headerlink" title="1. 初始化express做http服务器"></a>1. 初始化express做http服务器</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// cnpm install express-session</span></span><br><span class="line"><span class="comment">// cnpm install express</span></span><br><span class="line"><span class="keyword">var</span> express = <span class="built_in">require</span>(<span class="string">&#x27;express&#x27;</span>);</span><br><span class="line"><span class="keyword">var</span> bodyParser = <span class="built_in">require</span>(<span class="string">&#x27;body-parser&#x27;</span>);</span><br><span class="line"><span class="keyword">var</span> session = <span class="built_in">require</span>(<span class="string">&#x27;express-session&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> app = express();</span><br><span class="line"></span><br><span class="line"><span class="comment">// 设置body解析器</span></span><br><span class="line"><span class="keyword">var</span> urlencodedParser = bodyParser.urlencoded(&#123; <span class="attr">extended</span>: <span class="literal">false</span> &#125;)</span><br><span class="line">app.use(bodyParser.json());</span><br><span class="line">app.use(bodyParser.urlencoded(&#123;</span><br><span class="line">  <span class="attr">extended</span>: <span class="literal">false</span></span><br><span class="line">&#125;));</span><br><span class="line"></span><br><span class="line"><span class="comment">// 访问静态资源</span></span><br><span class="line">app.use(express.static(path.resolve(__dirname, <span class="string">&#x27;../dist&#x27;</span>)));</span><br><span class="line"></span><br><span class="line"><span class="comment">// 设置session</span></span><br><span class="line">app.use(session(&#123;</span><br><span class="line">  <span class="attr">secret</span>:<span class="string">&#x27;today is a holiday&#x27;</span>,</span><br><span class="line">  <span class="attr">resave</span>:<span class="literal">true</span>,</span><br><span class="line">  <span class="attr">saveUninitialized</span>:<span class="literal">false</span>,</span><br><span class="line">  <span class="attr">cookie</span>:&#123;</span><br><span class="line">      <span class="attr">maxAge</span>:<span class="number">1000</span>*<span class="number">60</span>*<span class="number">10</span> <span class="comment">//过期时间设置(单位毫秒)</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;));</span><br><span class="line"></span><br><span class="line"><span class="comment">// 重定向到index.html文件中</span></span><br><span class="line">app.get(<span class="string">&#x27;/*&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">req, res</span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">&quot;get &quot;</span> + req.url);</span><br><span class="line">  res.sendFile(path.join(__dirname, <span class="string">&#x27;../dist&#x27;</span>, <span class="string">&#x27;index.html&#x27;</span>));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 监听</span></span><br><span class="line">app.listen(<span class="number">8081</span>, <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">&#x27;success listen... http://127.0.0.1:8081&#x27;</span>);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<h1 id="2-提供一个post处理函数"><a href="#2-提供一个post处理函数" class="headerlink" title="2. 提供一个post处理函数"></a>2. 提供一个post处理函数</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">app.post(<span class="string">&#x27;/login/regist&#x27;</span>,urlencodedParser,<span class="function"><span class="keyword">function</span>(<span class="params">req, res</span>)</span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">&quot;POST 请求 /login/regist &quot;</span> + req.body.username + <span class="string">&quot; &quot;</span> + req.body.password );</span><br><span class="line">  <span class="keyword">var</span> s = <span class="built_in">JSON</span>.stringify(&#123;</span><br><span class="line">      <span class="attr">code</span>: <span class="number">50001</span>,</span><br><span class="line">      <span class="attr">message</span>: <span class="string">&#x27;error code!&#x27;</span></span><br><span class="line">    &#125;);</span><br><span class="line">    res.send(s);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="3-md5-hash"><a href="#3-md5-hash" class="headerlink" title="3. md5 hash"></a>3. md5 hash</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> crypto = <span class="built_in">require</span>(<span class="string">&#x27;crypto&#x27;</span>);</span><br><span class="line"><span class="keyword">var</span> md5 = crypto.createHash(<span class="string">&#x27;md5&#x27;</span>);</span><br><span class="line"><span class="keyword">var</span> md5_passwd = md5.update(password).digest(<span class="string">&#x27;hex&#x27;</span>).toLowerCase();</span><br></pre></td></tr></table></figure>

<h1 id="4-mysql"><a href="#4-mysql" class="headerlink" title="4. mysql"></a>4. mysql</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> mysql      = <span class="built_in">require</span>(<span class="string">&#x27;mysql&#x27;</span>);</span><br><span class="line"><span class="keyword">var</span> connection = mysql.createConnection(&#123;</span><br><span class="line">  <span class="attr">host</span>     : <span class="string">&#x27;localhost&#x27;</span>,</span><br><span class="line">  <span class="attr">user</span>     : <span class="string">&#x27;usrnode&#x27;</span>,</span><br><span class="line">  <span class="attr">password</span> : <span class="string">&#x27;123456&#x27;</span>,</span><br><span class="line">  <span class="attr">port</span>: <span class="string">&#x27;3306&#x27;</span>,</span><br><span class="line">  <span class="attr">database</span>: <span class="string">&#x27;nodedb&#x27;</span>,</span><br><span class="line">&#125;);</span><br><span class="line">connection.connect();</span><br><span class="line">connection.query(sql, <span class="function"><span class="keyword">function</span> (<span class="params">error, results, fields</span>) </span>&#123;</span><br><span class="line">    cb(error, results, fields);</span><br><span class="line">  &#125;);</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="http://www.runoob.com/nodejs/nodejs-mysql.html">参考原文</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2018/11/20/2018/2018-11-20-nodejs-login/" data-id="ckrn3an6t000320xw5k3ag3mi" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/node-js/" rel="tag">node.js</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-2018/2018-11-13-cmake-usage" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/11/13/2018/2018-11-13-cmake-usage/" class="article-date">
  <time datetime="2018-11-12T16:00:00.000Z" itemprop="datePublished">2018-11-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/11/13/2018/2018-11-13-cmake-usage/">cmake入门</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>记录cmake常用方法</p>
<ul>
<li><a href="#%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C">基本操作</a></li>
<li><a href="#%E8%AE%BE%E7%BD%AE%E7%BC%96%E8%AF%91%E7%8E%AF%E5%A2%83">设置编译环境</a></li>
<li><a href="#%E5%8F%82%E6%95%B0%E8%AE%BE%E7%BD%AE">参数设置</a></li>
</ul>
<p>CMake是为了解决美国国家医学图书馆出资的Visible Human Project专案下的Insight Segmentation and Registration Toolkit （ITK） 软件的跨平台建构的需求而创造出来的，其设计受到了Ken Martin开发的pcmaker所影响。pcmaker当初则是为了支援Visualization Toolkit这个开放源代码的三维图形和视觉系统才出现的，今日VTK也采用了CMake。在设计CMake之时，Kitware公司的Bill Hoffman采用了pcmaker的一些重要想法，加上更多他自己的点子，想把GNU建构系统的一些功能整合进来。CMake最初的实作是在2000年中作的，在2001年初有了急速的进展，许多改良是来自其他把CMake整合到自己的系统中的开发者，比方说，采用CMake作为建构环境的VXL社群就贡献了很多重要的功能，Brad King为了支援CABLE和GCC-XML这套自动包装工具也加了几项功能，奇异公司的研发部门则用在内部的测试系统DART，还有一些功能是为了让VTK可以过渡到CMake和支援（“美国Los Alamos国家实验室”&amp;“洛斯阿拉莫斯国家实验室”）的Advanced Computing Lab的平行视觉系统ParaView而加的。</p>
<h1 id="官网的教程"><a href="#官网的教程" class="headerlink" title="官网的教程"></a>官网的教程</h1><p><a target="_blank" rel="noopener" href="https://cmake.org/cmake-tutorial/">传送门</a></p>
<p>本章节将会按照官方网站里面提到的步骤来学习cmake的基本用法。</p>
<h2 id="编译一个exe"><a href="#编译一个exe" class="headerlink" title="编译一个exe"></a>编译一个exe</h2><p>CMakeLists.txt</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cmake_minimum_required (VERSION 2.6)</span><br><span class="line">project (Tutorial)</span><br><span class="line">add_executable(Tutorial tutorial.cxx)</span><br></pre></td></tr></table></figure>

<p>tutorial.cpp</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// tutorial.cpp</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span> <span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> *argv[])</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="comment">//...</span></span><br><span class="line">  <span class="built_in">printf</span>(<span class="string">&quot;hello&quot;</span>);</span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="使用版本号定义"><a href="#使用版本号定义" class="headerlink" title="使用版本号定义"></a>使用版本号定义</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">cmake_minimum_required (VERSION 2.6)</span><br><span class="line">project (Tutorial)</span><br><span class="line"><span class="comment"># The version number.</span></span><br><span class="line"><span class="built_in">set</span> (Tutorial_VERSION_MAJOR 1)</span><br><span class="line"><span class="built_in">set</span> (Tutorial_VERSION_MINOR 0)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># configure a header file to pass some of the CMake settings</span></span><br><span class="line"><span class="comment"># to the source code</span></span><br><span class="line">configure_file (</span><br><span class="line">  <span class="string">&quot;<span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/TutorialConfig.h.in&quot;</span></span><br><span class="line">  <span class="string">&quot;<span class="variable">$&#123;PROJECT_BINARY_DIR&#125;</span>/TutorialConfig.h&quot;</span></span><br><span class="line">  )</span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the binary tree to the search path for include files</span></span><br><span class="line"><span class="comment"># so that we will find TutorialConfig.h</span></span><br><span class="line">include_directories(<span class="string">&quot;<span class="variable">$&#123;PROJECT_BINARY_DIR&#125;</span>&quot;</span>)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the executable</span></span><br><span class="line">add_executable(Tutorial tutorial.cxx)</span><br></pre></td></tr></table></figure>

<p>TutorialConfig.h.in文件中编写这个内容</p>
<figure class="highlight h"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// the configured options and settings for Tutorial</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@</span></span><br></pre></td></tr></table></figure>

<p>最后将会生成代码TutorialConfig.h</p>
<p>在源码里面我们能很方便的使用</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;TutorialConfig.h&quot;</span></span></span><br><span class="line">    <span class="built_in">fprintf</span>(stdout,<span class="string">&quot;%s Version %d.%d\n&quot;</span>,</span><br><span class="line">            argv[<span class="number">0</span>],</span><br><span class="line">            Tutorial_VERSION_MAJOR,</span><br><span class="line">            Tutorial_VERSION_MINOR);</span><br></pre></td></tr></table></figure>

<h2 id="使用自己的lib库"><a href="#使用自己的lib库" class="headerlink" title="使用自己的lib库"></a>使用自己的lib库</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># should we use our own math functions?</span></span><br><span class="line">option (USE_MYMATH </span><br><span class="line">        <span class="string">&quot;Use tutorial provided math implementation&quot;</span> ON) </span><br><span class="line">add_library(MathFunctions mysqrt.cxx)</span><br><span class="line">include_directories (<span class="string">&quot;<span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/MathFunctions&quot;</span>)</span><br><span class="line">add_subdirectory (MathFunctions) </span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the executable</span></span><br><span class="line">add_executable (Tutorial tutorial.cxx)</span><br><span class="line">target_link_libraries (Tutorial MathFunctions)</span><br><span class="line"></span><br><span class="line"><span class="comment"># add the MathFunctions library?</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="keyword">if</span> (USE_MYMATH)</span><br><span class="line">  include_directories (<span class="string">&quot;<span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/MathFunctions&quot;</span>)</span><br><span class="line">  add_subdirectory (MathFunctions)</span><br><span class="line">  <span class="built_in">set</span> (EXTRA_LIBS <span class="variable">$&#123;EXTRA_LIBS&#125;</span> MathFunctions)</span><br><span class="line">endif (USE_MYMATH)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the executable</span></span><br><span class="line">add_executable (Tutorial tutorial.cxx)</span><br><span class="line">target_link_libraries (Tutorial  <span class="variable">$&#123;EXTRA_LIBS&#125;</span>)</span><br></pre></td></tr></table></figure>

<p>在代码里面可以使用刚刚的宏开关</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">ifdef</span> USE_MYMATH</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;MathFunctions.h&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">ifdef</span> USE_MYMATH</span></span><br><span class="line">  <span class="keyword">double</span> outputValue = <span class="built_in">mysqrt</span>(inputValue);</span><br><span class="line"><span class="meta">#<span class="meta-keyword">else</span></span></span><br><span class="line">  <span class="keyword">double</span> outputValue = <span class="built_in">sqrt</span>(inputValue);</span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></span><br></pre></td></tr></table></figure>


<h2 id="安装与测试"><a href="#安装与测试" class="headerlink" title="安装与测试"></a>安装与测试</h2><p>将安装的文件拷贝到指定的目录中。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">install (TARGETS MathFunctions DESTINATION bin)</span><br><span class="line">install (FILES MathFunctions.h DESTINATION include)</span><br><span class="line"></span><br><span class="line"><span class="comment"># add the install targets</span></span><br><span class="line">install (TARGETS Tutorial DESTINATION bin)</span><br><span class="line">install (FILES <span class="string">&quot;<span class="variable">$&#123;PROJECT_BINARY_DIR&#125;</span>/TutorialConfig.h&quot;</span>        </span><br><span class="line">         DESTINATION include)</span><br></pre></td></tr></table></figure>

<p>先引入这个模块</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">include(CTest)</span><br></pre></td></tr></table></figure>

<p>通过编写的宏来检查当前的测试是否能通过。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">define</span> a macro to simplify adding tests, then use it</span></span><br><span class="line"><span class="built_in">macro</span> (do_test arg result)</span><br><span class="line">  <span class="built_in">add_test</span> (TutorialComp$&#123;arg&#125; Tutorial $&#123;arg&#125;)</span><br><span class="line">  <span class="built_in">set_tests_properties</span> (TutorialComp$&#123;arg&#125;</span><br><span class="line">    PROPERTIES PASS_REGULAR_EXPRESSION $&#123;result&#125;)</span><br><span class="line"><span class="built_in">endmacro</span> (do_test)</span><br><span class="line"> </span><br><span class="line"><span class="meta"># do a bunch of result based tests</span></span><br><span class="line"><span class="built_in">do_test</span> (<span class="number">25</span> <span class="string">&quot;25 is 5&quot;</span>)</span><br><span class="line"><span class="built_in">do_test</span> (<span class="number">-25</span> <span class="string">&quot;-25 is 0&quot;</span>)</span><br></pre></td></tr></table></figure>

<h2 id="平台检查"><a href="#平台检查" class="headerlink" title="平台检查"></a>平台检查</h2><p>添加检查</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># does this system provide the log and exp functions?</span></span><br><span class="line">include (CheckFunctionExists)</span><br><span class="line">check_function_exists (<span class="built_in">log</span> HAVE_LOG)</span><br><span class="line">check_function_exists (exp HAVE_EXP)</span><br></pre></td></tr></table></figure>

<p>通过这个来检查当前平台是否存在log,exp函数，如果有将直接在代码里面使用系统的支持函数。</p>
<p>console</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// does the platform provide exp and log functions?</span></span><br><span class="line"><span class="meta">#cmakedefine HAVE_LOG</span></span><br><span class="line"><span class="meta">#cmakedefine HAVE_EXP</span></span><br></pre></td></tr></table></figure>

<p>代码</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// if we have both log and exp then use them</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">if</span> defined (HAVE_LOG) &amp;&amp; defined (HAVE_EXP)</span></span><br><span class="line">  result = <span class="built_in">exp</span>(<span class="built_in">log</span>(x)*<span class="number">0.5</span>);</span><br><span class="line"><span class="meta">#<span class="meta-keyword">else</span> <span class="comment">// otherwise use an iterative approach</span></span></span><br><span class="line">  . . .</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="自定义选项"><a href="#自定义选项" class="headerlink" title="自定义选项"></a>自定义选项</h2><p>用于制作条件打开某个功能。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 设置一个OctSvr的开关，默认设置为OFF</span></span><br><span class="line">option (OctSvr <span class="string">&quot;OctSvr&quot;</span> OFF)</span><br><span class="line"><span class="keyword">if</span> (OctSvr)</span><br><span class="line">      <span class="comment"># 做一些开关内的事情。</span></span><br><span class="line">endif (OctSvr)</span><br><span class="line"><span class="comment"># 在命令行中手动的打开或这关闭</span></span><br><span class="line">cmake -DOctSvr=[ON|OFF(default)] </span><br></pre></td></tr></table></figure>

<h2 id="开启c-17"><a href="#开启c-17" class="headerlink" title="开启c++ 17"></a>开启c++ 17</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">// windows</span><br><span class="line">    add_compile_options(<span class="string">&quot;/std:c++17&quot;</span>)	</span><br><span class="line">// linux</span><br><span class="line">SET(CMAKE_CXX_FLAGS <span class="string">&quot;<span class="variable">$&#123;CMAKE_CXX_FLAGS&#125;</span> -std=c++17 &quot;</span>)</span><br></pre></td></tr></table></figure>

<h2 id="目录文件批量添加"><a href="#目录文件批量添加" class="headerlink" title="目录文件批量添加"></a>目录文件批量添加</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">file(GLOB pbc_SRC <span class="string">&quot;3rd/pbc/src/*.h&quot;</span> <span class="string">&quot;3rd/pbc/src/*.c&quot;</span> )</span><br></pre></td></tr></table></figure>

<h2 id="设置cmake工程依赖关系"><a href="#设置cmake工程依赖关系" class="headerlink" title="设置cmake工程依赖关系"></a>设置cmake工程依赖关系</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">add_subdirectory(common)</span><br><span class="line">add_subdirectory(chuanqi_robot)</span><br><span class="line">add_dependencies(chuanqi_robot common)</span><br></pre></td></tr></table></figure>

<h2 id="执行程序"><a href="#执行程序" class="headerlink" title="执行程序"></a>执行程序</h2><h2 id="添加一个生成文件和生成器"><a href="#添加一个生成文件和生成器" class="headerlink" title="添加一个生成文件和生成器"></a>添加一个生成文件和生成器</h2><p>这个实例是编写了一个table生成的execute文件，生成一个开方的文件出来。然后通过cmake集成到编译过程中。<br>MakeTable.cxx文件中实现了一个可以生成table的一个程序</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// A simple program that builds a sqrt table </span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;stdlib.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;math.h&gt;</span></span></span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span> <span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> *argv[])</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">int</span> i;</span><br><span class="line">  <span class="keyword">double</span> result;</span><br><span class="line"> </span><br><span class="line">  <span class="comment">// make sure we have enough arguments</span></span><br><span class="line">  <span class="keyword">if</span> (argc &lt; <span class="number">2</span>)</span><br><span class="line">    &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">  </span><br><span class="line">  <span class="comment">// open the output file</span></span><br><span class="line">  FILE *fout = <span class="built_in">fopen</span>(argv[<span class="number">1</span>],<span class="string">&quot;w&quot;</span>);</span><br><span class="line">  <span class="keyword">if</span> (!fout)</span><br><span class="line">    &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">  </span><br><span class="line">  <span class="comment">// create a source file with a table of square roots</span></span><br><span class="line">  <span class="built_in">fprintf</span>(fout,<span class="string">&quot;double sqrtTable[] = &#123;\n&quot;</span>);</span><br><span class="line">  <span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; <span class="number">10</span>; ++i)</span><br><span class="line">    &#123;</span><br><span class="line">    result = <span class="built_in">sqrt</span>(<span class="keyword">static_cast</span>&lt;<span class="keyword">double</span>&gt;(i));</span><br><span class="line">    <span class="built_in">fprintf</span>(fout,<span class="string">&quot;%g,\n&quot;</span>,result);</span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line">  <span class="comment">// close the table with a zero</span></span><br><span class="line">  <span class="built_in">fprintf</span>(fout,<span class="string">&quot;0&#125;;\n&quot;</span>);</span><br><span class="line">  <span class="built_in">fclose</span>(fout);</span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>这里的cmakefile.txt文件中说明要如何生成这个MakeTable，之后添加了一个add_custom_command的命令，用于将一个table.h生成出来。<br>通过include_directories将本地目录加入到include搜索目录，并且在编译MathFunctions这个library库的时候，添加上Table.h的依赖。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># first we add the executable that generates the table</span></span><br><span class="line">add_executable(MakeTable MakeTable.cxx)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the command to generate the source code</span></span><br><span class="line">add_custom_command (</span><br><span class="line">  OUTPUT <span class="variable">$&#123;CMAKE_CURRENT_BINARY_DIR&#125;</span>/Table.h</span><br><span class="line">  COMMAND MakeTable <span class="variable">$&#123;CMAKE_CURRENT_BINARY_DIR&#125;</span>/Table.h</span><br><span class="line">  DEPENDS MakeTable</span><br><span class="line">  )</span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the binary tree directory to the search path for </span></span><br><span class="line"><span class="comment"># include files</span></span><br><span class="line">include_directories( <span class="variable">$&#123;CMAKE_CURRENT_BINARY_DIR&#125;</span> )</span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the main library</span></span><br><span class="line">add_library(MathFunctions mysqrt.cxx <span class="variable">$&#123;CMAKE_CURRENT_BINARY_DIR&#125;</span>/Table.h  )</span><br></pre></td></tr></table></figure>

<h2 id="现在完整的cmake"><a href="#现在完整的cmake" class="headerlink" title="现在完整的cmake"></a>现在完整的cmake</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># CMakeLists.txt</span></span><br><span class="line">cmake_minimum_required (VERSION 2.6)</span><br><span class="line">project (Tutorial)</span><br><span class="line">include(CTest)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># The version number.</span></span><br><span class="line"><span class="built_in">set</span> (Tutorial_VERSION_MAJOR 1)</span><br><span class="line"><span class="built_in">set</span> (Tutorial_VERSION_MINOR 0)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># does this system provide the log and exp functions?</span></span><br><span class="line">include (<span class="variable">$&#123;CMAKE_ROOT&#125;</span>/Modules/CheckFunctionExists.cmake)</span><br><span class="line"> </span><br><span class="line">check_function_exists (<span class="built_in">log</span> HAVE_LOG)</span><br><span class="line">check_function_exists (exp HAVE_EXP)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># should we use our own math functions</span></span><br><span class="line">option(USE_MYMATH </span><br><span class="line">  <span class="string">&quot;Use tutorial provided math implementation&quot;</span> ON)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># configure a header file to pass some of the CMake settings</span></span><br><span class="line"><span class="comment"># to the source code</span></span><br><span class="line">configure_file (</span><br><span class="line">  <span class="string">&quot;<span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/TutorialConfig.h.in&quot;</span></span><br><span class="line">  <span class="string">&quot;<span class="variable">$&#123;PROJECT_BINARY_DIR&#125;</span>/TutorialConfig.h&quot;</span></span><br><span class="line">  )</span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the binary tree to the search path for include files</span></span><br><span class="line"><span class="comment"># so that we will find TutorialConfig.h</span></span><br><span class="line">include_directories (<span class="string">&quot;<span class="variable">$&#123;PROJECT_BINARY_DIR&#125;</span>&quot;</span>)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the MathFunctions library?</span></span><br><span class="line"><span class="keyword">if</span> (USE_MYMATH)</span><br><span class="line">  include_directories (<span class="string">&quot;<span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/MathFunctions&quot;</span>)</span><br><span class="line">  add_subdirectory (MathFunctions)</span><br><span class="line">  <span class="built_in">set</span> (EXTRA_LIBS <span class="variable">$&#123;EXTRA_LIBS&#125;</span> MathFunctions)</span><br><span class="line">endif (USE_MYMATH)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the executable</span></span><br><span class="line">add_executable (Tutorial tutorial.cxx)</span><br><span class="line">target_link_libraries (Tutorial  <span class="variable">$&#123;EXTRA_LIBS&#125;</span>)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># add the install targets</span></span><br><span class="line">install (TARGETS Tutorial DESTINATION bin)</span><br><span class="line">install (FILES <span class="string">&quot;<span class="variable">$&#123;PROJECT_BINARY_DIR&#125;</span>/TutorialConfig.h&quot;</span>        </span><br><span class="line">         DESTINATION include)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># does the application run</span></span><br><span class="line">add_test (TutorialRuns Tutorial 25)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># does the usage message work?</span></span><br><span class="line">add_test (TutorialUsage Tutorial)</span><br><span class="line">set_tests_properties (TutorialUsage</span><br><span class="line">  PROPERTIES </span><br><span class="line">  PASS_REGULAR_EXPRESSION <span class="string">&quot;Usage:.*number&quot;</span></span><br><span class="line">  )</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"><span class="comment">#define a macro to simplify adding tests</span></span><br><span class="line">macro (do_test arg result)</span><br><span class="line">  add_test (TutorialComp<span class="variable">$&#123;arg&#125;</span> Tutorial <span class="variable">$&#123;arg&#125;</span>)</span><br><span class="line">  set_tests_properties (TutorialComp<span class="variable">$&#123;arg&#125;</span></span><br><span class="line">    PROPERTIES PASS_REGULAR_EXPRESSION <span class="variable">$&#123;result&#125;</span></span><br><span class="line">    )</span><br><span class="line">endmacro (do_test)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># do a bunch of result based tests</span></span><br><span class="line">do_test (4 <span class="string">&quot;4 is 2&quot;</span>)</span><br><span class="line">do_test (9 <span class="string">&quot;9 is 3&quot;</span>)</span><br><span class="line">do_test (5 <span class="string">&quot;5 is 2.236&quot;</span>)</span><br><span class="line">do_test (7 <span class="string">&quot;7 is 2.645&quot;</span>)</span><br><span class="line">do_test (25 <span class="string">&quot;25 is 5&quot;</span>)</span><br><span class="line">do_test (-25 <span class="string">&quot;-25 is 0&quot;</span>)</span><br><span class="line">do_test (0.0001 <span class="string">&quot;0.0001 is 0.01&quot;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>btw: 今天发现在mac机器上dll文件换了个后缀，叫做*.dylib文件。^_^</p>
<h1 id="基本操作"><a href="#基本操作" class="headerlink" title="基本操作"></a>基本操作</h1><p>文件名称</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">CMakeLists.txt</span><br></pre></td></tr></table></figure>

<p>开启调试模式</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cmake </span><br><span class="line">-DCMAKE_BUILD_TYPE=Debug</span><br></pre></td></tr></table></figure>

<p>use clang compiler</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang</span><br></pre></td></tr></table></figure>

<p>包含子目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">add_subdirectory(GameServer)</span><br></pre></td></tr></table></figure>

<p>命令行在windows里面生成工程。</p>
<figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">mkdir</span> build</span><br><span class="line"><span class="built_in">cd</span> build</span><br><span class="line">cmake -G &quot;Visual Studio <span class="number">14</span> <span class="number">2015</span>&quot; ..</span><br></pre></td></tr></table></figure>

<p>设定windows下的输出目录</p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/pandamohist/p/14502789.html">设置变量</a></p>
<figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># 指定可执行程序输出目录</span><br><span class="line"><span class="built_in">set</span>(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG 	$&#123;publish_bin_debug&#125;)</span><br><span class="line"><span class="built_in">set</span>(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE 	$&#123;publish_bin_release&#125;)</span><br><span class="line">  		# 指定 库文件输出目录</span><br><span class="line"><span class="built_in">set</span>(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG 	$&#123;publish_lib_debug&#125;)</span><br><span class="line"><span class="built_in">set</span>(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RLEASE 	$&#123;publish_lib_release&#125;)</span><br></pre></td></tr></table></figure>

<h1 id="设置编译环境"><a href="#设置编译环境" class="headerlink" title="设置编译环境"></a>设置编译环境</h1><p>include *h path</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">include_directories(<span class="variable">$&#123;CMAKE_CURRENT_LIST_DIR&#125;</span>/luabind/)</span><br></pre></td></tr></table></figure>

<p>include lib path</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">link_directories(<span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/external/lua/lib/)</span><br></pre></td></tr></table></figure>

<p>设置输出目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">set</span>(BUILD_TARGET_DIR <span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/build/run/)</span><br><span class="line"><span class="built_in">set</span>(BUILD_LIB_DIR <span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/build/lib/)</span><br><span class="line">SET(EXECUTABLE_OUTPUT_PATH <span class="variable">$&#123;BUILD_TARGET_DIR&#125;</span>/server/)</span><br></pre></td></tr></table></figure>

<p>拷贝文件夹，配置文件拷贝</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">file(COPY <span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/tools/ DESTINATION  <span class="variable">$&#123;BUILD_TARGET_DIR&#125;</span> PATTERN .svn EXCLUDE)</span><br><span class="line">configure_file(<span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/CenterServer/srcs/csstring.xml <span class="variable">$&#123;BUILD_TARGET_DIR&#125;</span>/ct/csstring.xml COPYONLY)</span><br></pre></td></tr></table></figure>

<p>使用环境变量</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">include_directories( <span class="variable">$ENV</span>&#123;path_libuv&#125;/include )</span><br></pre></td></tr></table></figure>

<p>执行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">execute_process(COMMAND  bash release.sh WORKING_DIRECTORY  <span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/config_new/design/ )</span><br></pre></td></tr></table></figure>

<h1 id="参数设置"><a href="#参数设置" class="headerlink" title="参数设置"></a>参数设置</h1><p>cxx flag</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-Wall 开启全部warning</span><br><span class="line">-Wextra  among other stuff</span><br><span class="line">-fdiagnostics-color=auto </span><br><span class="line">-std=c++14 </span><br><span class="line">-fsanitize=address 启用clang里面的内存检查</span><br></pre></td></tr></table></figure>

<p>设置依赖关系</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">add_dependencies(server luabind)</span><br></pre></td></tr></table></figure>

<p>搜索文件列表</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">file(GLOB_RECURSE GAME_SERVER src *.cpp *.h *.hpp *.xml )</span><br><span class="line">file(GLOB variable [RELATIVE path] [globbing expressions]...)</span><br><span class="line">file(GLOB_RECURSE variable [RELATIVE path]</span><br><span class="line">[FOLLOW_SYMLINKS] [globbing expressions]...)</span><br><span class="line">https://cmake.org/cmake/<span class="built_in">help</span>/v3.0/<span class="built_in">command</span>/file.html?highlight=file</span><br><span class="line"></span><br><span class="line">add_executable(server <span class="variable">$&#123;GAME_SERVER&#125;</span>)</span><br></pre></td></tr></table></figure>

<p>设置使用了lib库</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">target_link_libraries(server crypt crypto rt z libprotobuf.a)</span><br></pre></td></tr></table></figure>

<p>操作系统判断</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">IF (CMAKE_SYSTEM_NAME MATCHES <span class="string">&quot;Windows&quot;</span>)</span><br><span class="line">   ...</span><br><span class="line">ELSE ()</span><br><span class="line">   ...</span><br><span class="line">ENDIF (CMAKE_SYSTEM_NAME MATCHES <span class="string">&quot;Windows&quot;</span>)</span><br></pre></td></tr></table></figure>

<p>windows常用的编译选项</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">add_definitions(-DWIN32)</span><br><span class="line">add_definitions(-DWIN32_LEAN_AND_MEAN)</span><br><span class="line">add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)</span><br><span class="line">add_definitions(-D_CRT_SECURE_NO_WARNINGS)</span><br><span class="line"></span><br><span class="line">target_link_libraries(client ws2_32.lib)</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2018/11/13/2018/2018-11-13-cmake-usage/" data-id="ckrn3an6n000020xwbtl14f8m" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/C/" rel="tag">C++</a></li></ul>

    </footer>
  </div>
  
</article>


  


  <nav id="page-nav">
    
    <a class="extend prev" rel="prev" href="/page/4/">&amp;laquo; Prev</a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/3/">3</a><a class="page-number" href="/page/4/">4</a><span class="page-number current">5</span>
  </nav>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/3D/" rel="tag">3D</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/AI/" rel="tag">AI</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/" rel="tag">C++</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Game/" rel="tag">Game</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Go/" rel="tag">Go</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux/" rel="tag">Linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Math/" rel="tag">Math</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Server/" rel="tag">Server</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Unreal-Engine4/" rel="tag">Unreal Engine4</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/" rel="tag">git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/golang/" rel="tag">golang</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/guitar/" rel="tag">guitar</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/node-js/" rel="tag">node.js</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/" rel="tag">protobuf</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/" rel="tag">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/recast/" rel="tag">recast</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/" rel="tag">redis</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/type/" rel="tag">type</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vscode/" rel="tag">vscode</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%BF%90%E7%BB%B4/" rel="tag">运维</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/3D/" style="font-size: 10px;">3D</a> <a href="/tags/AI/" style="font-size: 11.67px;">AI</a> <a href="/tags/C/" style="font-size: 15px;">C++</a> <a href="/tags/Game/" style="font-size: 18.33px;">Game</a> <a href="/tags/Go/" style="font-size: 13.33px;">Go</a> <a href="/tags/Linux/" style="font-size: 13.33px;">Linux</a> <a href="/tags/Math/" style="font-size: 11.67px;">Math</a> <a href="/tags/Server/" style="font-size: 16.67px;">Server</a> <a href="/tags/Unreal-Engine4/" style="font-size: 10px;">Unreal Engine4</a> <a href="/tags/git/" style="font-size: 10px;">git</a> <a href="/tags/golang/" style="font-size: 20px;">golang</a> <a href="/tags/guitar/" style="font-size: 10px;">guitar</a> <a href="/tags/node-js/" style="font-size: 10px;">node.js</a> <a href="/tags/protobuf/" style="font-size: 10px;">protobuf</a> <a href="/tags/python/" style="font-size: 10px;">python</a> <a href="/tags/recast/" style="font-size: 11.67px;">recast</a> <a href="/tags/redis/" style="font-size: 10px;">redis</a> <a href="/tags/type/" style="font-size: 10px;">type</a> <a href="/tags/vscode/" style="font-size: 10px;">vscode</a> <a href="/tags/%E8%BF%90%E7%BB%B4/" style="font-size: 16.67px;">运维</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/07/">July 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/06/">June 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/04/">April 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/03/">March 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/01/">January 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/12/">December 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/11/">November 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/11/">November 2018</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2021/07/19/2021/2021-07-19-etcd-learn/">go-etcd阅读笔记</a>
          </li>
        
          <li>
            <a href="/2021/07/19/2021/2021-07-19-socketop-learn/">REUSEPORT-REUSEADDR-学习</a>
          </li>
        
          <li>
            <a href="/2021/06/22/2021/2021-06-22-go-ethereum-learn/">go-ethereum阅读笔记</a>
          </li>
        
          <li>
            <a href="/2021/06/21/2021/2021-06-21-server%E6%B5%8B%E8%AF%95%E5%B7%A5%E5%85%B7/">server测试工具</a>
          </li>
        
          <li>
            <a href="/2021/06/09/2021/2021-06-09-pprof-doc/">go-pprof</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2021 Abel Sean<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>




  </div>
</body>
</html>